<template>
  <div class="app-container">
    <el-table border v-loading="loading" :data="productBomList" border>
      <el-table-column label="序号" type="index" width="50" />
      <el-table-column label="物料编号" width="150" align="center" prop="itemCode" :show-overflow-tooltip="true" />
      <el-table-column label="物料名称" width="200" align="center" prop="itemName" :show-overflow-tooltip="true" />
      <el-table-column label="规格型号" align="center" prop="specification" :show-overflow-tooltip="true" />
      <el-table-column label="单位" align="center" prop="unitOfMeasure" />
      <el-table-column
        v-for="col in columnsConfig"
        :key="col.prop"
        :label="col.label"
        :prop="col.prop"
        :width="col.width"
        :align="col.align"
        v-if="col.show"
      >
      </el-table-column>
      <!--      <el-table-column label="使用比例" align="center" prop="quantity"/>-->
      <el-table-column label="规格" align="center" prop="model" :show-overflow-tooltip="true" />
      <el-table-column label="规格单位" align="center" width="80" prop="specificationUnit" />
      <el-table-column label="预计使用量" align="center" width="120" prop="used" fixed="right">
        <template slot-scope="scope">
          {{ ((Number(scope.row.used) || 0) * (Number(scope.row.attr3) || 0)).toFixed(2) }}
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listTaskBom } from '@/api/mes/pro/proTaskBom';
import { getColumnsConfigKey } from '@/api/system/columnsconfig';

export default {
  name: 'WorkorderItemList',
  dicts: ['mes_item_product'],
  data() {
    return {
      columnsConfig: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料需求
      productBomList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskId: this.taskId
      }
    };
  },
  props: {
    taskId: undefined
  },
  watch: {
    taskId(v) {
      this.queryParams.taskId = v;
      this.getList();
    }
  },
  created() {
    this.getItemBase();
    this.getList();
  },
  methods: {
    /** 查询生产工单BOM组成列表 */
    getList() {
      this.loading = true;
      listTaskBom(this.queryParams).then(response => {
        this.productBomList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getItemBase() {
      getColumnsConfigKey('MdItem_Base').then(res => {
        this.columnsConfig = JSON.parse(res.data);
      });
    }
  }
};
</script>
